/*
 * Table.cpp
 *
 *  Created on: 13-Feb-2013
 *      Author: abhijeet
 */

#include "Table.h"

Table::Table() {

	//Table to store the Register type instruction
	RTable.insert(StringPair("0000", "ADD"));
	RTable.insert(StringPair("0001", "SUB"));
	RTable.insert(StringPair("0010", "MUL"));
	RTable.insert(StringPair("0011", "AND"));
	RTable.insert(StringPair("0100", "OR"));
	RTable.insert(StringPair("0101", "XOR"));
	RTable.insert(StringPair("0110", "NOR"));
	RTable.insert(StringPair("0111", "SLT"));
	RTable.insert(StringPair("1000", "ADDI"));
	RTable.insert(StringPair("1001", "ANDI"));
	RTable.insert(StringPair("1010", "ORI"));
	RTable.insert(StringPair("1011", "XORI"));

	//Table to store the Immediate type instruction
	ITable.insert(StringPair("0000", "J"));
	ITable.insert(StringPair("0001", "JR"));
	ITable.insert(StringPair("0010", "BEQ"));
	ITable.insert(StringPair("0011", "BLTZ"));
	ITable.insert(StringPair("0100", "BGTZ"));
	ITable.insert(StringPair("0101", "BREAK"));
	ITable.insert(StringPair("0110", "SW"));
	ITable.insert(StringPair("0111", "LW"));
	ITable.insert(StringPair("1000", "SLL"));
	ITable.insert(StringPair("1001", "SRL"));
	ITable.insert(StringPair("1010", "SRA"));
	ITable.insert(StringPair("1011", "NOP"));

	//constIt = symbolTable.find("abhijeet");

	//cout << " -- " << constIt->second << endl;

}

Table::~Table() {
	// TODO Auto-generated destructor stub
}

int Table::GetUpcodeName(char *upcode, char * upCodeName, InstType type) {

	if (type == R) {
		it = RTable.find(upcode);
		//cout << " upcode received: " << upcode << endl;

		if (it != RTable.end()) {
			strcpy(upCodeName, it->second);
			it != RTable.end();
			return 1;
		} else {
			return 0;
		}
	} else {
		it = ITable.find(upcode);
		//cout << " upcode received: " << upcode << endl;

		if (it != ITable.end()) {
			strcpy(upCodeName, it->second);
			it != ITable.end();
			return 1;
		} else {
			return 0;
		}
	}

}
